package cn.com.hhrcw.service.impl;

import cn.com.hhrcw.entity.SysUserDepart;
import cn.com.hhrcw.mapper.MySysUserDepartMapper;
import cn.com.hhrcw.service.ISysUserDepartService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author gaoruiyi
 * @since 2020-11-06
 */
@Service("SysUserDepartServiceImpl")
@Transactional(rollbackFor = Exception.class)
public class SysUserDepartServiceImpl extends ServiceImpl<MySysUserDepartMapper, SysUserDepart> implements ISysUserDepartService {

    /**
     * 企业关联用户
     * @param userId
     * @param companyId
     */
    @Override
    public boolean referenceUser(String userId, String companyId){
        SysUserDepart sysUserDepart = this.lambdaQuery().eq(SysUserDepart::getUserId, userId).eq(SysUserDepart::getDepId, companyId).one();
        sysUserDepart = sysUserDepart == null ? new SysUserDepart() : sysUserDepart;
        sysUserDepart.setUserId(userId);
        sysUserDepart.setDepId(companyId);
        return this.saveOrUpdate(sysUserDepart);
    }
}
